package userlimitController

import (
	"arabApi/app/api/controllers"
	"arabApi/app/api/controllers/CFun"
	"arabApi/app/api/requests/CRequest"
	"arabApi/app/api/requests/userlimitRequest"
	"arabApi/app/api/services/userLimitService"
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
)

type RoleMenu struct {
	controllers.BaseAPIController
}

func (RoleMenu) RoleAdd(c *gin.Context) {
	r := userlimitRequest.RoleMenuAdd{}
	if err := c.ShouldBindBodyWith(&r, binding.JSON); err != nil {
		CFun.Ajax_return_fail(c, CFun.WithMsg("解析错误"+err.Error()))
		return
	}

	//if ok := requests.Validate(c, &r, userlimitRequest.CheckUserRoleAdd); !ok {
	//	return
	//}

	if ok := userLimitService.RoleMenuAdd(r); !ok {
		CFun.Ajax_return_fail(c, CFun.WithMsg("添加失败"))
	} else {
		CFun.Ajax_return_success(c, CFun.WithMsg("添加成功"))
	}

}

func (RoleMenu) Menu(c *gin.Context) {
	r := CRequest.Oid{}

	// 解析 JSON 请求
	if err := c.ShouldBindQuery(&r); err != nil {
		CFun.Ajax_return_fail(c, CFun.WithMsg(err.Error()))
		return
	}

	ids := userLimitService.Menu1()

	CFun.Ajax_return_success(c, CFun.WithData(ids))

}

func (RoleMenu) UserRole(c *gin.Context) {
	r := CRequest.Oid{}

	// 解析 JSON 请求
	if err := c.ShouldBindQuery(&r); err != nil {
		CFun.Ajax_return_fail(c, CFun.WithMsg(err.Error()))
		return
	}
	ids := userLimitService.RoleMenu(r.Id)
	CFun.Ajax_return_success(c, CFun.WithData(ids))
}
